package artid.com.arttogo.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.ImageLoader;
import java.util.List;
import artid.com.arttogo.R;
import artid.com.arttogo.bean.CelebritySealInfoParser;
import artid.com.arttogo.utils.NetUtils;
import artid.com.arttogo.view.DynamicHeightImageView;

/**
 * 名人艺术家适配器
 */

public class CelebritySealInfo_Adapter extends BaseAdapter {
    private Context mContext;
    private List<CelebritySealInfoParser.CelebritySealInfo_ImageInfo> list;

    public CelebritySealInfo_Adapter(Context mContext, List<CelebritySealInfoParser.CelebritySealInfo_ImageInfo> list) {
        this.mContext = mContext;
        this.list = list;
    }

    public void notifyData(List<CelebritySealInfoParser.CelebritySealInfo_ImageInfo> list) {
        // TODO Auto-generated method stub
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder = null;
        View v = convertView;
        if (v == null) {
            holder = new ViewHolder();
            v = LayoutInflater.from(mContext).inflate(R.layout.item_celebritysealinfo, null);
            holder.img=(DynamicHeightImageView) v.findViewById(R.id.itemCelebritysealInfo_img);
            holder.describe=(TextView) v.findViewById(R.id.itemCelebritysealInfo_describe);
            v.setTag(holder);
        } else {
            holder = (ViewHolder) v.getTag();
        }
        holder.img.setHeight(Integer.parseInt(list.get(position).getHeight()) );
        ImageLoader.getInstance().displayImage(list.get(position).getPath()
                + "_"+ (Integer.parseInt(NetUtils.getDisplayMetrics((Activity)mContext).get(NetUtils.DM_WIDTH)) /2) + "x10.png",holder.img);
        holder.describe.setText(list.get(position).getName());
        return v;
    }
    class ViewHolder {
        DynamicHeightImageView img;
        TextView describe;
    }
}
